home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17998 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.dtc.hp.com!hplntx!hplabs!hp-pcd!hpcvca!jg
  2. From: jg@cv.hp.com (Joe Gilray)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Errors using TArrayAsVector, "unable to find constructor".  BC++ 4.5.
  5. Date: 18 Apr 1996 01:04:21 GMT
  6. Organization: Hewlett-Packard Company, Corvallis, Oregon USA
  7. Message-ID: <4l44el$62@hpcvca.cv.hp.com>
  8. References: <3170528B.7641@novell.com>
  9. NNTP-Posting-Host: hpcvcef.cv.hp.com
  10. X-Newsreader: TIN [version 1.2 021193BETA PL3]
  11.  
  12. Max Norris (mnorris@novell.com) wrote:
  13. ....
  14.  
  15. : template <class Type>
  16. : class Sorter:public TArrayAsVector<Type>  {
  17. : private:
  18. :     int temp;
  19. : public:
  20. :     Sorter() {};
  21. :     virtual void sort()=0;
  22. :     int operator == (const Sorter& p) const
  23. :     { return (p.temp==temp) ? 1:0; };
  24. : };
  25.  
  26. Max,
  27.  
  28. Each constructor must call construct its base classes by calling a base class
  29. constructor in its initialization list.  If you don't explicitly say which
  30. constructor to use, the compiler will automatically insert a call to the
  31. base class's default (no-argument) ctor.
  32.  
  33. This is what is going on in the ctor for Sorter, unfortunately Sorter's base
  34. class, TArrayAsVector<Type> doesn't have a default ctor.  To remedy the problem
  35. put a call to the desired ctor in the initialization list of your Sorter 
  36. ctor, something like this:
  37.  
  38.   Sorter() : TArrayAsVector<Type>(10) {}
  39.  
  40. -Joe Gilray
  41.